﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;

namespace DAO
{
    public class PhieuThuePhongDAO
    {
        public static DataTable GetAll()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select p.TenPhong, pt.NgayThuePhong,pt.MaPhieuThue, pt.MaPhong From Phong p, PhieuThuePhong pt where p.MaPhong = pt.MaPhong";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable Get()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select * From PhieuThuePhong";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable PhongThueTheoMa(int mapt)
        {
            DataProvider dp = new DataProvider();
            string sql = "Select MaPhong From PhieuThuePhong Where MaPhieuThue = " + mapt + "";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable PhieuThueChuaThanhToan()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select pt.MaPhieuThue, p.TenPhong, pt.DonGiaThue, pt.SoNgayThue, pt.NgayBatDauThue From PhieuThuePhong pt, Phong p Where p.MaPhong = pt.MaPhong and pt.TinhTrang = 0";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static void ThemPhieuThuePhong(PhieuThuePhongDTO pt)
        {
            string sql = string.Format("INSERT INTO PhieuThuePhong(MaPhieuThue, MaPhong,NgayThuePhong) VALUES (" + pt.MaPhieuThue + "," + pt.MaPhong + ",'" + pt.NgayThuePhong  + "')");
            DataProvider.ExecuteNonQuery(sql);
        }

        public static void CapNhatPhieuThue(int mapt, int mahd)
        {
            string sql = string.Format("Update PhieuThuePhong Set MaHoaDon=" + mahd + ", TinhTrang=1 Where MaPhieuThue = " + mapt + "");
            DataProvider.ExecuteNonQuery(sql);
        }
    }
}
